package com.dao;

import java.util.List;
import java.util.ArrayList;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.SqlUtils;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;

import com.model.Apiario;
import com.model.Racas;
import com.model.TipoColmeia;
import com.model.TiposOrigem;

import com.model.Exame;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table EXAME.
*/
public class ExameDao extends AbstractDao<Exame, Long> {

    public static final String TABLENAME = "EXAME";

    /**
     * Properties of entity Exame.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_idExame");
        public final static Property NumeroColonia = new Property(1, String.class, "numeroColonia", false, "NUMERO_COLONIA");
        public final static Property Cor = new Property(2, String.class, "cor", false, "COR");
        public final static Property ColoniaOrigem = new Property(3, String.class, "coloniaOrigem", false, "COLONIA_ORIGEM");
        public final static Property DataFormacao = new Property(4, String.class, "dataFormacao", false, "DATA_FORMACAO");
        public final static Property DataInstalacao = new Property(5, String.class, "dataInstalacao", false, "DATA_INSTALACAO");
        public final static Property Qualidade = new Property(6, String.class, "qualidade", false, "QUALIDADE");
        public final static Property ProbEnxemaecao = new Property(7, boolean.class, "probEnxemaecao", false, "PROB_ENXEMAECAO");
        public final static Property Possuiredutoralvado = new Property(8, boolean.class, "possuiredutoralvado", false, "POSSUIREDUTORALVADO");
        public final static Property Possuitampoexcluidor = new Property(9, boolean.class, "possuitampoexcluidor", false, "POSSUITAMPOEXCLUIDOR");
        public final static Property Captpolen = new Property(10, boolean.class, "captpolen", false, "CAPTPOLEN");
        public final static Property Quantidadealsa = new Property(11, Integer.class, "quantidadealsa", false, "QUANTIDADEALSA");
        public final static Property Nalimentacoes = new Property(12, Integer.class, "nalimentacoes", false, "NALIMENTACOES");
        public final static Property NivelReservas = new Property(13, Integer.class, "nivelReservas", false, "NIVEL_RESERVAS");
        public final static Property QtdAlimenta = new Property(14, Integer.class, "qtdAlimenta", false, "QTD_ALIMENTA");
        public final static Property MotivoDesact = new Property(15, String.class, "motivoDesact", false, "MOTIVO_DESACT");
        public final static Property NivelDefesa = new Property(16, String.class, "nivelDefesa", false, "NIVEL_DEFESA");
        public final static Property Obs = new Property(17, String.class, "obs", false, "OBS");
        public final static Property TipoExtrado = new Property(18, String.class, "tipoExtrado", false, "TIPO_EXTRADO");
        public final static Property PosX = new Property(19, Integer.class, "posX", false, "POS_X");
        public final static Property PosY = new Property(20, Integer.class, "posY", false, "POS_Y");
        public final static Property Codabar = new Property(21, String.class, "codabar", false, "CODABAR");
        public final static Property Etiqrdif = new Property(22, String.class, "etiqrdif", false, "ETIQRDIF");
        public final static Property TempInterior = new Property(23, Integer.class, "TempInterior", false, "TEMP_INTERIOR");
        public final static Property HumidInterior = new Property(24, Integer.class, "humidInterior", false, "HUMID_INTERIOR");
        public final static Property NivRuido = new Property(25, Integer.class, "NivRuido", false, "NIV_RUIDO");
        public final static Property LocalizaLatid = new Property(26, String.class, "localizaLatid", false, "LOCALIZA_LATID");
        public final static Property LocalizaLongitude = new Property(27, String.class, "localizaLongitude", false, "LOCALIZA_LONGITUDE");
        public final static Property Desactiva = new Property(28, boolean.class, "desactiva", false, "DESACTIVA");
        public final static Property Grupo = new Property(29, Integer.class, "grupo", false, "GRUPO");
        public final static Property Foto = new Property(30, String.class, "foto", false, "FOTO");
        public final static Property Tabdetectvaroa = new Property(31, boolean.class, "tabdetectvaroa", false, "TABDETECTVAROA");
        public final static Property ProdelMel = new Property(32, Integer.class, "prodelMel", false, "PRODEL_MEL");
        public final static Property ProdPropolis = new Property(33, Integer.class, "prodPropolis", false, "PROD_PROPOLIS");
        public final static Property ProdPolen = new Property(34, Integer.class, "prodPolen", false, "PROD_POLEN");
        public final static Property ApiarioOrigemId = new Property(35, long.class, "apiarioOrigemId", false, "APIARIO_ORIGEM_ID");
        public final static Property TipoOrigemId = new Property(36, long.class, "tipoOrigemId", false, "TIPO_ORIGEM_ID");
        public final static Property TipoNucleoId = new Property(37, long.class, "tipoNucleoId", false, "TIPO_NUCLEO_ID");
        public final static Property RacaId = new Property(38, long.class, "racaId", false, "RACA_ID");
        public final static Property ApicultorId = new Property(39, long.class, "apicultorId", false, "APICULTOR_ID");
        public final static Property Date = new Property(40, java.util.Date.class, "date", false, "DATE");
    };

    private DaoSession daoSession;

    private Query<Exame> apiario_ApiarioExameQuery;
    private Query<Exame> apiario_ApiarioOrigemExameQuery;
    private Query<Exame> tiposOrigem_TipoOrigemExameQuery;
    private Query<Exame> tipoColmeia_TipoColmeiaExameQuery;
    private Query<Exame> racas_RacaExameQuery;

    public ExameDao(DaoConfig config) {
        super(config);
    }
    
    public ExameDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'EXAME' (" + //
                "'_idExame' INTEGER PRIMARY KEY ASC AUTOINCREMENT NOT NULL ," + // 0: id
                "'NUMERO_COLONIA' TEXT NOT NULL ," + // 1: numeroColonia
                "'COR' TEXT NOT NULL ," + // 2: cor
                "'COLONIA_ORIGEM' TEXT NOT NULL ," + // 3: coloniaOrigem
                "'DATA_FORMACAO' TEXT NOT NULL ," + // 4: dataFormacao
                "'DATA_INSTALACAO' TEXT NOT NULL ," + // 5: dataInstalacao
                "'QUALIDADE' TEXT NOT NULL ," + // 6: qualidade
                "'PROB_ENXEMAECAO' INTEGER NOT NULL ," + // 7: probEnxemaecao
                "'POSSUIREDUTORALVADO' INTEGER NOT NULL ," + // 8: possuiredutoralvado
                "'POSSUITAMPOEXCLUIDOR' INTEGER NOT NULL ," + // 9: possuitampoexcluidor
                "'CAPTPOLEN' INTEGER NOT NULL ," + // 10: captpolen
                "'QUANTIDADEALSA' INTEGER," + // 11: quantidadealsa
                "'NALIMENTACOES' INTEGER," + // 12: nalimentacoes
                "'NIVEL_RESERVAS' INTEGER," + // 13: nivelReservas
                "'QTD_ALIMENTA' INTEGER," + // 14: qtdAlimenta
                "'MOTIVO_DESACT' TEXT," + // 15: motivoDesact
                "'NIVEL_DEFESA' TEXT," + // 16: nivelDefesa
                "'OBS' TEXT," + // 17: obs
                "'TIPO_EXTRADO' TEXT," + // 18: tipoExtrado
                "'POS_X' INTEGER," + // 19: posX
                "'POS_Y' INTEGER," + // 20: posY
                "'CODABAR' TEXT," + // 21: codabar
                "'ETIQRDIF' TEXT," + // 22: etiqrdif
                "'TEMP_INTERIOR' INTEGER," + // 23: TempInterior
                "'HUMID_INTERIOR' INTEGER," + // 24: humidInterior
                "'NIV_RUIDO' INTEGER," + // 25: NivRuido
                "'LOCALIZA_LATID' TEXT," + // 26: localizaLatid
                "'LOCALIZA_LONGITUDE' TEXT," + // 27: localizaLongitude
                "'DESACTIVA' INTEGER NOT NULL ," + // 28: desactiva
                "'GRUPO' INTEGER," + // 29: grupo
                "'FOTO' TEXT," + // 30: foto
                "'TABDETECTVAROA' INTEGER NOT NULL ," + // 31: tabdetectvaroa
                "'PRODEL_MEL' INTEGER," + // 32: prodelMel
                "'PROD_PROPOLIS' INTEGER," + // 33: prodPropolis
                "'PROD_POLEN' INTEGER," + // 34: prodPolen
                "'APIARIO_ORIGEM_ID' INTEGER NOT NULL ," + // 35: apiarioOrigemId
                "'TIPO_ORIGEM_ID' INTEGER NOT NULL ," + // 36: tipoOrigemId
                "'TIPO_NUCLEO_ID' INTEGER NOT NULL ," + // 37: tipoNucleoId
                "'RACA_ID' INTEGER NOT NULL ," + // 38: racaId
                "'APICULTOR_ID' INTEGER NOT NULL ," + // 39: apicultorId
                "'DATE' INTEGER);"); // 40: date
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'EXAME'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Exame entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindString(2, entity.getNumeroColonia());
        stmt.bindString(3, entity.getCor());
        stmt.bindString(4, entity.getColoniaOrigem());
        stmt.bindString(5, entity.getDataFormacao());
        stmt.bindString(6, entity.getDataInstalacao());
        stmt.bindString(7, entity.getQualidade());
        stmt.bindLong(8, entity.getProbEnxemaecao() ? 1l: 0l);
        stmt.bindLong(9, entity.getPossuiredutoralvado() ? 1l: 0l);
        stmt.bindLong(10, entity.getPossuitampoexcluidor() ? 1l: 0l);
        stmt.bindLong(11, entity.getCaptpolen() ? 1l: 0l);
 
        Integer quantidadealsa = entity.getQuantidadealsa();
        if (quantidadealsa != null) {
            stmt.bindLong(12, quantidadealsa);
        }
 
        Integer nalimentacoes = entity.getNalimentacoes();
        if (nalimentacoes != null) {
            stmt.bindLong(13, nalimentacoes);
        }
 
        Integer nivelReservas = entity.getNivelReservas();
        if (nivelReservas != null) {
            stmt.bindLong(14, nivelReservas);
        }
 
        Integer qtdAlimenta = entity.getQtdAlimenta();
        if (qtdAlimenta != null) {
            stmt.bindLong(15, qtdAlimenta);
        }
 
        String motivoDesact = entity.getMotivoDesact();
        if (motivoDesact != null) {
            stmt.bindString(16, motivoDesact);
        }
 
        String nivelDefesa = entity.getNivelDefesa();
        if (nivelDefesa != null) {
            stmt.bindString(17, nivelDefesa);
        }
 
        String obs = entity.getObs();
        if (obs != null) {
            stmt.bindString(18, obs);
        }
 
        String tipoExtrado = entity.getTipoExtrado();
        if (tipoExtrado != null) {
            stmt.bindString(19, tipoExtrado);
        }
 
        Integer posX = entity.getPosX();
        if (posX != null) {
            stmt.bindLong(20, posX);
        }
 
        Integer posY = entity.getPosY();
        if (posY != null) {
            stmt.bindLong(21, posY);
        }
 
        String codabar = entity.getCodabar();
        if (codabar != null) {
            stmt.bindString(22, codabar);
        }
 
        String etiqrdif = entity.getEtiqrdif();
        if (etiqrdif != null) {
            stmt.bindString(23, etiqrdif);
        }
 
        Integer TempInterior = entity.getTempInterior();
        if (TempInterior != null) {
            stmt.bindLong(24, TempInterior);
        }
 
        Integer humidInterior = entity.getHumidInterior();
        if (humidInterior != null) {
            stmt.bindLong(25, humidInterior);
        }
 
        Integer NivRuido = entity.getNivRuido();
        if (NivRuido != null) {
            stmt.bindLong(26, NivRuido);
        }
 
        String localizaLatid = entity.getLocalizaLatid();
        if (localizaLatid != null) {
            stmt.bindString(27, localizaLatid);
        }
 
        String localizaLongitude = entity.getLocalizaLongitude();
        if (localizaLongitude != null) {
            stmt.bindString(28, localizaLongitude);
        }
        stmt.bindLong(29, entity.getDesactiva() ? 1l: 0l);
 
        Integer grupo = entity.getGrupo();
        if (grupo != null) {
            stmt.bindLong(30, grupo);
        }
 
        String foto = entity.getFoto();
        if (foto != null) {
            stmt.bindString(31, foto);
        }
        stmt.bindLong(32, entity.getTabdetectvaroa() ? 1l: 0l);
 
        Integer prodelMel = entity.getProdelMel();
        if (prodelMel != null) {
            stmt.bindLong(33, prodelMel);
        }
 
        Integer prodPropolis = entity.getProdPropolis();
        if (prodPropolis != null) {
            stmt.bindLong(34, prodPropolis);
        }
 
        Integer prodPolen = entity.getProdPolen();
        if (prodPolen != null) {
            stmt.bindLong(35, prodPolen);
        }
        stmt.bindLong(36, entity.getApiarioOrigemId());
        stmt.bindLong(37, entity.getTipoOrigemId());
        stmt.bindLong(38, entity.getTipoNucleoId());
        stmt.bindLong(39, entity.getRacaId());
        stmt.bindLong(40, entity.getApicultorId());
 
        java.util.Date date = entity.getDate();
        if (date != null) {
            stmt.bindLong(41, date.getTime());
        }
    }

    @Override
    protected void attachEntity(Exame entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public Exame readEntity(Cursor cursor, int offset) {
        Exame entity = new Exame( //
            cursor.getLong(offset + 0), // id
            cursor.getString(offset + 1), // numeroColonia
            cursor.getString(offset + 2), // cor
            cursor.getString(offset + 3), // coloniaOrigem
            cursor.getString(offset + 4), // dataFormacao
            cursor.getString(offset + 5), // dataInstalacao
            cursor.getString(offset + 6), // qualidade
            cursor.getShort(offset + 7) != 0, // probEnxemaecao
            cursor.getShort(offset + 8) != 0, // possuiredutoralvado
            cursor.getShort(offset + 9) != 0, // possuitampoexcluidor
            cursor.getShort(offset + 10) != 0, // captpolen
            cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11), // quantidadealsa
            cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12), // nalimentacoes
            cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13), // nivelReservas
            cursor.isNull(offset + 14) ? null : cursor.getInt(offset + 14), // qtdAlimenta
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // motivoDesact
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // nivelDefesa
            cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // obs
            cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // tipoExtrado
            cursor.isNull(offset + 19) ? null : cursor.getInt(offset + 19), // posX
            cursor.isNull(offset + 20) ? null : cursor.getInt(offset + 20), // posY
            cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21), // codabar
            cursor.isNull(offset + 22) ? null : cursor.getString(offset + 22), // etiqrdif
            cursor.isNull(offset + 23) ? null : cursor.getInt(offset + 23), // TempInterior
            cursor.isNull(offset + 24) ? null : cursor.getInt(offset + 24), // humidInterior
            cursor.isNull(offset + 25) ? null : cursor.getInt(offset + 25), // NivRuido
            cursor.isNull(offset + 26) ? null : cursor.getString(offset + 26), // localizaLatid
            cursor.isNull(offset + 27) ? null : cursor.getString(offset + 27), // localizaLongitude
            cursor.getShort(offset + 28) != 0, // desactiva
            cursor.isNull(offset + 29) ? null : cursor.getInt(offset + 29), // grupo
            cursor.isNull(offset + 30) ? null : cursor.getString(offset + 30), // foto
            cursor.getShort(offset + 31) != 0, // tabdetectvaroa
            cursor.isNull(offset + 32) ? null : cursor.getInt(offset + 32), // prodelMel
            cursor.isNull(offset + 33) ? null : cursor.getInt(offset + 33), // prodPropolis
            cursor.isNull(offset + 34) ? null : cursor.getInt(offset + 34), // prodPolen
            cursor.getLong(offset + 35), // apiarioOrigemId
            cursor.getLong(offset + 36), // tipoOrigemId
            cursor.getLong(offset + 37), // tipoNucleoId
            cursor.getLong(offset + 38), // racaId
            cursor.getLong(offset + 39), // apicultorId
            cursor.isNull(offset + 40) ? null : new java.util.Date(cursor.getLong(offset + 40)) // date
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Exame entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setNumeroColonia(cursor.getString(offset + 1));
        entity.setCor(cursor.getString(offset + 2));
        entity.setColoniaOrigem(cursor.getString(offset + 3));
        entity.setDataFormacao(cursor.getString(offset + 4));
        entity.setDataInstalacao(cursor.getString(offset + 5));
        entity.setQualidade(cursor.getString(offset + 6));
        entity.setProbEnxemaecao(cursor.getShort(offset + 7) != 0);
        entity.setPossuiredutoralvado(cursor.getShort(offset + 8) != 0);
        entity.setPossuitampoexcluidor(cursor.getShort(offset + 9) != 0);
        entity.setCaptpolen(cursor.getShort(offset + 10) != 0);
        entity.setQuantidadealsa(cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11));
        entity.setNalimentacoes(cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12));
        entity.setNivelReservas(cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13));
        entity.setQtdAlimenta(cursor.isNull(offset + 14) ? null : cursor.getInt(offset + 14));
        entity.setMotivoDesact(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setNivelDefesa(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setObs(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setTipoExtrado(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setPosX(cursor.isNull(offset + 19) ? null : cursor.getInt(offset + 19));
        entity.setPosY(cursor.isNull(offset + 20) ? null : cursor.getInt(offset + 20));
        entity.setCodabar(cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21));
        entity.setEtiqrdif(cursor.isNull(offset + 22) ? null : cursor.getString(offset + 22));
        entity.setTempInterior(cursor.isNull(offset + 23) ? null : cursor.getInt(offset + 23));
        entity.setHumidInterior(cursor.isNull(offset + 24) ? null : cursor.getInt(offset + 24));
        entity.setNivRuido(cursor.isNull(offset + 25) ? null : cursor.getInt(offset + 25));
        entity.setLocalizaLatid(cursor.isNull(offset + 26) ? null : cursor.getString(offset + 26));
        entity.setLocalizaLongitude(cursor.isNull(offset + 27) ? null : cursor.getString(offset + 27));
        entity.setDesactiva(cursor.getShort(offset + 28) != 0);
        entity.setGrupo(cursor.isNull(offset + 29) ? null : cursor.getInt(offset + 29));
        entity.setFoto(cursor.isNull(offset + 30) ? null : cursor.getString(offset + 30));
        entity.setTabdetectvaroa(cursor.getShort(offset + 31) != 0);
        entity.setProdelMel(cursor.isNull(offset + 32) ? null : cursor.getInt(offset + 32));
        entity.setProdPropolis(cursor.isNull(offset + 33) ? null : cursor.getInt(offset + 33));
        entity.setProdPolen(cursor.isNull(offset + 34) ? null : cursor.getInt(offset + 34));
        entity.setApiarioOrigemId(cursor.getLong(offset + 35));
        entity.setTipoOrigemId(cursor.getLong(offset + 36));
        entity.setTipoNucleoId(cursor.getLong(offset + 37));
        entity.setRacaId(cursor.getLong(offset + 38));
        entity.setApicultorId(cursor.getLong(offset + 39));
        entity.setDate(cursor.isNull(offset + 40) ? null : new java.util.Date(cursor.getLong(offset + 40)));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Exame entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Exame entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "apiarioExame" to-many relationship of Apiario. */
    public List<Exame> _queryApiario_ApiarioExame(long apicultorId) {
        synchronized (this) {
            if (apiario_ApiarioExameQuery == null) {
                QueryBuilder<Exame> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ApicultorId.eq(null));
                queryBuilder.orderRaw("DATE ASC");
                apiario_ApiarioExameQuery = queryBuilder.build();
            }
        }
        Query<Exame> query = apiario_ApiarioExameQuery.forCurrentThread();
        query.setParameter(0, apicultorId);
        return query.list();
    }

    /** Internal query to resolve the "apiarioOrigemExame" to-many relationship of Apiario. */
    public List<Exame> _queryApiario_ApiarioOrigemExame(long apiarioOrigemId) {
        synchronized (this) {
            if (apiario_ApiarioOrigemExameQuery == null) {
                QueryBuilder<Exame> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ApiarioOrigemId.eq(null));
                queryBuilder.orderRaw("DATE ASC");
                apiario_ApiarioOrigemExameQuery = queryBuilder.build();
            }
        }
        Query<Exame> query = apiario_ApiarioOrigemExameQuery.forCurrentThread();
        query.setParameter(0, apiarioOrigemId);
        return query.list();
    }

    /** Internal query to resolve the "tipoOrigemExame" to-many relationship of TiposOrigem. */
    public List<Exame> _queryTiposOrigem_TipoOrigemExame(long tipoOrigemId) {
        synchronized (this) {
            if (tiposOrigem_TipoOrigemExameQuery == null) {
                QueryBuilder<Exame> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.TipoOrigemId.eq(null));
                queryBuilder.orderRaw("DATE ASC");
                tiposOrigem_TipoOrigemExameQuery = queryBuilder.build();
            }
        }
        Query<Exame> query = tiposOrigem_TipoOrigemExameQuery.forCurrentThread();
        query.setParameter(0, tipoOrigemId);
        return query.list();
    }

    /** Internal query to resolve the "tipoColmeiaExame" to-many relationship of TipoColmeia. */
    public List<Exame> _queryTipoColmeia_TipoColmeiaExame(long tipoNucleoId) {
        synchronized (this) {
            if (tipoColmeia_TipoColmeiaExameQuery == null) {
                QueryBuilder<Exame> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.TipoNucleoId.eq(null));
                queryBuilder.orderRaw("DATE ASC");
                tipoColmeia_TipoColmeiaExameQuery = queryBuilder.build();
            }
        }
        Query<Exame> query = tipoColmeia_TipoColmeiaExameQuery.forCurrentThread();
        query.setParameter(0, tipoNucleoId);
        return query.list();
    }

    /** Internal query to resolve the "racaExame" to-many relationship of Racas. */
    public List<Exame> _queryRacas_RacaExame(long racaId) {
        synchronized (this) {
            if (racas_RacaExameQuery == null) {
                QueryBuilder<Exame> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.RacaId.eq(null));
                queryBuilder.orderRaw("DATE ASC");
                racas_RacaExameQuery = queryBuilder.build();
            }
        }
        Query<Exame> query = racas_RacaExameQuery.forCurrentThread();
        query.setParameter(0, racaId);
        return query.list();
    }

    private String selectDeep;

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getApiarioDao().getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T1", daoSession.getTiposOrigemDao().getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T2", daoSession.getTipoColmeiaDao().getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T3", daoSession.getRacasDao().getAllColumns());
            builder.append(" FROM EXAME T");
            builder.append(" LEFT JOIN APIARIO T0 ON T.'APICULTOR_ID'=T0.'_idApiario'");
            builder.append(" LEFT JOIN TIPOS_ORIGEM T1 ON T.'TIPO_ORIGEM_ID'=T1.'_idTiposOrigem'");
            builder.append(" LEFT JOIN TIPO_COLMEIA T2 ON T.'TIPO_NUCLEO_ID'=T2.'_idTipoColmeia'");
            builder.append(" LEFT JOIN RACAS T3 ON T.'RACA_ID'=T3.'_idRaca'");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected Exame loadCurrentDeep(Cursor cursor, boolean lock) {
        Exame entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        Apiario apiario = loadCurrentOther(daoSession.getApiarioDao(), cursor, offset);
         if(apiario != null) {
            entity.setApiario(apiario);
        }
        offset += daoSession.getApiarioDao().getAllColumns().length;

        TiposOrigem tiposOrigem = loadCurrentOther(daoSession.getTiposOrigemDao(), cursor, offset);
         if(tiposOrigem != null) {
            entity.setTiposOrigem(tiposOrigem);
        }
        offset += daoSession.getTiposOrigemDao().getAllColumns().length;

        TipoColmeia tipoColmeia = loadCurrentOther(daoSession.getTipoColmeiaDao(), cursor, offset);
         if(tipoColmeia != null) {
            entity.setTipoColmeia(tipoColmeia);
        }
        offset += daoSession.getTipoColmeiaDao().getAllColumns().length;

        Racas racas = loadCurrentOther(daoSession.getRacasDao(), cursor, offset);
         if(racas != null) {
            entity.setRacas(racas);
        }

        return entity;    
    }

    public Exame loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();
        
        String[] keyArray = new String[] { key.toString() };
        Cursor cursor = db.rawQuery(sql, keyArray);
        
        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }
    
    /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
    public List<Exame> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<Exame> list = new ArrayList<Exame>(count);
        
        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }
    
    protected List<Exame> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<Exame> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
}
